var vm = new Vue({
    el: "#abnormalReport",
    data: {
        deviceList: [],
        userList: [],
        exceptionList: [],
        exception: null,
        facilites: null,
        receiver: null,
        description: null
    },
    ready: function() {

        var _self = this
        //初始化下拉选项
        this.$http.post(host +"abnormalReport/getList",null,{emulateJSON: true}).then(function(res) {
            if(res.ok && res.body.result) {
                _self.exceptionList = res.body.exceptionList
                _self.userList = res.body.userList
                _self.deviceList = res.body.deviceList

                _self.$nextTick(function(){
                    layui.use('form', function(){
                        var form = layui.form
                        form.render()
                    })
                })

                var userArr = []
                for (var i in _self.userList) {
                    userArr.push({"name": _self.userList[i].NAME, "value": _self.userList[i].AD_USER_ID})
                }

                var formSelects = layui.formSelects;
                formSelects.data('receiver', 'local', {
                    arr: userArr
                })

            } else {
                layer.msg("初始化数据失败")
            }
        });

    },
    methods: {
        // 关闭
        close: function() {
            var index = parent.layer.getFrameIndex(window.name);
            parent.layer.close(index);
        },
        // 提交
        submit: function() {
            var _self = this
            var exception = $("#exception").val();
            var facilites = $("#facilites").val();
            var formSelects = layui.formSelects;
            var receiver = formSelects.value('receiver', 'valStr');

            if (null == exception || '' == exception) {
                layer.msg("请选择异常原因")
                return
            }

            if (null == facilites || '' == facilites) {
                layer.msg("请选择问题设备")
                return
            }

            if (null == receiver || '' == receiver) {
                layer.msg("请选择接收人员")
                return
            }

            this.$http.post(host +"abnormalReport/addExceptionLog",{"exception": exception,
                "facilites": facilites, "receiver": receiver, "description": this.description},
                {emulateJSON: true}).then(function(res) {
                if(res.ok && res.body.result) {
                    layer.msg("异常上报成功！")
                    _self.close()
                } else {
                    layer.msg("异常上报失败！")
                }
            });
        }
    }
});